/**
 * Created by Administrator on 14-1-7.
 */
(function($) {
    var arkflow = $.arkflow;

    // 创建编辑框
    arkflow.editors.SelectEditor = Base.extend({
        constructor : function(arg) {
            this.arg = arg;
        },
        init : function(props, k, div, src, r) {
            this._props = props;
            this._k = k;
            this._div = div;
            this._src = src;
            this._r = r;
            var me = this;
            var sle = $('<select  style="width:100%;"/>').val(props[this._k].value).change(function() {
                props[me._k].value = $(this).val();
            }).appendTo('#' + this._div);

            if ( typeof this.arg === 'string') {
                $.ajax({
                    type : "GET",
                    url : this.arg,
                    success : function(data) {
                        var opts = eval(data);
                        if (opts && opts.length) {
                            for (var idx = 0; idx < opts.length; idx++) {
                                sle.append('<option value="' + opts[idx].value + '">' + opts[idx].name + '</option>');
                            }
                            sle.val(me._props[me._k].value);
                        }
                    }
                });
            } else {
                for (var idx = 0; idx < this.arg.length; idx++) {
                    sle.append('<option value="' + this.arg[idx].value + '">' + this.arg[idx].name + '</option>');
                }
                sle.val(this._props[this._k].value);
            }

            $('#' + this._div).data('editor', this);
        },
        destroy : function() {
            var me = this;
            $('#' + this._div + ' input').each(function() {
                me._props[me._k].value = $(this).val();
            });
        }
    });

})(jQuery);
